import axios from 'axios'
import { RootThunkAction } from '..'

export const getArticle = (id: number):RootThunkAction => {
  console.log('发请求', id)
  // 发异步请求
  return async (dispatch) => {
    const res = await axios.get('http://geek.itheima.net/v1_0/articles?channel_id=' + id + '&timestamp=' + Date.now())
    console.log(res.data.data.results)
    dispatch({
      type: 'article/SET_ARTICLES',
      initState: res.data.data.results
    })
  }
}
